#include "Precompiled.h"
#include "SceneManagerLogic.h"

#include "SceneLogic.h"
#include "../Common/SceneManager.h"
#include "../Common/EntityLogicManager.h"

namespace Game {
namespace Logic {

SceneManagerLogic::SceneManagerLogic() :
        sceneLogic(NULL) {
}

SceneManagerLogic::~SceneManagerLogic() {
}

const RTTI& SceneManagerLogic::GetEntityRTTI() const {
    return SceneManager::rtti;
}

void SceneManagerLogic::Update(Entity* gameEntity, const float& elapsedTime) {
    SceneManager* sceneManager = static_cast<SceneManager*>(gameEntity);
    SceneManagerIterator it(sceneManager);
    for (; it(); ++it) {
        Scene* scene = *it;
        if (scene->GetEnabled()) {
            this->sceneLogic->Update(scene, elapsedTime);
        }
    }
}

void SceneManagerLogic::OnEntityLogicManagerChanged() {
    IEntityLogic* gameLogic = this->GetEntityLogicManager()->GetEntityLogic(Scene::rtti);
    this->sceneLogic = safe_pointer_cast<SceneLogic>(gameLogic);
}

}
}